Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location access via JavaScript #28

Merged
merged 11 commits into from
Dec 2, 2024
Merged

Location access via JavaScript #28

merged 11 commits into from
Dec 2, 2024

Conversation

joemasilotti
Copy link
Member

@joemasilotti joemasilotti commented Apr 5, 2024

This PR configures the web view and WebFragment to access the user's location via JavaScript.

The first time the user's location is accessed the following appears:

Xnapper-2024-04-05-11 13 05

If accepted, WebFragment reloads the page. When the location is accessed a second time the following appears:

Xnapper-2024-04-05-11 13 25

If the permissions in the manifest file are commented out the following appears when accessing the user's location:

Xnapper-2024-04-05-11 13 15

Note that this only works against HTTPS websites, so you will need to tunnel via ngrok for Chrome to expose the user's location.

The following Stimulus controller was used to test the location access:

// public/javascript/controllers/location_controller.js

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  request(event) {
    event.preventDefault()

    navigator.geolocation.getCurrentPosition(
      this.success.bind(this),
      this.failure.bind(this),
      {enableHighAccuracy: true}
    )
  }

  success(position) {
    const {latitude, longitude} = position.coords
    alert(`${latitude}, ${longitude}`)
  }

  failure(error) {
    alert(`Could not get your location: ${error.message}.`)
  }
}

jayohms and others added 10 commits April 25, 2024 13:51
* main:
  Present better looking Material dialogs for WebView alert and confirm dialogs
  Allow camera capture by default if the accept type explicitly allows images
* main: (63 commits)
  Update to the latest gradle plugin
  Include Turbo Native Android in the user agent substring for backwards compatibilty with existing apps
  Change Turbo Native to Hotwire Native in user agent.
  Update HotwireNavigation.kt
  Remove old docs
  Update README.md
  Revert "Add repositories to each build script"
  Add repositories to each build script
  Disable the gradle configuration cache due to incompatibility with the signing plugin
  Add the signing plugin
  Add Sonatype (Maven Central) publishing support
  Readme updates
  Add publishing build script for the navigation-fragments module
  Remove Strada references
  Update demo site url
  Update android plugin dependencies
  Update CI workflow actions
  Update logo filename
  Update raster launcher icon
  Update vector launcher icon
  ...

# Conflicts:
#	demo/src/main/kotlin/dev/hotwire/demo/features/web/WebFragment.kt
… the HotwireWebChromeClient if the app has declared location permission(s) are declared in the app manifest.
* main:
  Fix dialog fragment navigation issues. This fixes regressions when refactoring the Navigator to use a single instance across a navigation host. The topmost DialogFragment is not available from the NavigatorHost.childFragmentManager, since it is added directly to the Activity's window instead.
  Fix tests
  Fix lifecycle crash/timing issues when the Activity is recreated (such as during config changes)
  Add API doc
  Allow an app to check whether a navigator or its host are ready for navigation
  Provide the WebView system information in an easy to access way.
@jayohms jayohms merged commit 83a61c5 into main Dec 2, 2024
1 check passed
@jayohms jayohms deleted the location-access branch December 2, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants